package com.kingwang.study.spring.security.demo.security.token.session.impl;


import com.kingwang.study.spring.security.demo.security.token.session.AbstractTokenSession;
import com.kingwang.study.spring.security.demo.security.token.session.TokenSessionManager;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;

/**
 * Token会话内存实现
 */
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode(callSuper = true)
public class InMemoryTokenSession extends AbstractTokenSession {
    @Getter
    private final String id;

    @Getter
    private final String type;

    @Getter
    private final String token;

    @Getter
    @Setter
    private LocalDateTime creationTime;

    @Getter
    @Setter
    private UserDetails userDetails;

    private final TokenSessionManager sessionManager;

    @Override
    public void destroy() {
        this.sessionManager.removeSession(this);
    }
}
